//
//  BaseLeftSideNavController.m
//  Campus
//
//  Created by hzyd-wlj on 14-9-9.
//  Copyright (c) 2014年 hzyd. All rights reserved.
//

#import "BaseLeftSideNavController.h"
#import "REFrostedViewController.h"
#import "BaseViewController.h"

@interface BaseLeftSideNavController ()<UINavigationControllerDelegate>

@end

@implementation BaseLeftSideNavController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognized:)];
//    [self.view addGestureRecognizer:self.panGestureRecognizer];
     self.delegate = self;
}

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    self.panGestureRecognizer.enabled = NO;
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(BaseViewController *)viewController animated:(BOOL)animated
{
    if ([self.viewControllers count] == 1) {
        self.panGestureRecognizer.enabled = YES;
        __weak typeof(self)weakSelf = self;
        [viewController addLeftButtonWithImage:[UIImage imageNamed:@"侧边栏"] actionBlock:^{
            [weakSelf.frostedViewController presentMenuViewController];
        }];
    }
}


#pragma mark Gesture recognizer
- (void)panGestureRecognized:(UIPanGestureRecognizer *)sender
{
    // Dismiss keyboard (optional)
    //
    [self.view endEditing:YES];
    [self.frostedViewController.view endEditing:YES];
    
    // Present the view controller
    //
    [self.frostedViewController panGestureRecognized:sender];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
